Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shallow-clone

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shallow-clone

Creates a shallow clone of any JavaScript value.

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.5M
decreased by-61.49%
Maintainers
2
Weekly downloads
 
Created

What is shallow-clone?

The shallow-clone npm package is designed to create shallow copies of various JavaScript data types, such as objects, arrays, and other native types. It is useful for cases where you need a new object with the same properties as the original but without deep copying nested structures.

What are shallow-clone's main functionalities?

Cloning Objects

Creates a shallow copy of an object. Changes to nested objects in the original will reflect in the clone.

const shallowClone = require('shallow-clone');
const obj = { a: 1, b: { c: 2 } };
const clonedObj = shallowClone(obj);
console.log(clonedObj); // { a: 1, b: { c: 2 } }

Cloning Arrays

Creates a shallow copy of an array. Changes to nested arrays in the original will reflect in the clone.

const shallowClone = require('shallow-clone');
const arr = [1, 2, [3, 4]];
const clonedArr = shallowClone(arr);
console.log(clonedArr); // [1, 2, [3, 4]]

Cloning Dates

Creates a shallow copy of a Date object, resulting in a new Date object with the same time.

const shallowClone = require('shallow-clone');
const date = new Date();
const clonedDate = shallowClone(date);
console.log(clonedDate); // outputs cloned date object

Cloning Regular Expressions

Creates a shallow copy of a RegExp object, including its flags and lastIndex property.

const shallowClone = require('shallow-clone');
const regex = /test/gi;
const clonedRegex = shallowClone(regex);
console.log(clonedRegex); // outputs cloned RegExp object

Other packages similar to shallow-clone

Keywords

FAQs

Package last updated on 16 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc